/*
 * @Descripttion:
 * @version:
 * @Author: 麦冬果果
 * @Date: 2021-04-14 16:47:52
 * @LastEditors: 麦冬果果
 * @LastEditTime: 2021-04-15 08:57:24
 */
package utils

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/util/gconv"
)

var (
	Model = g.DB("default").Model("sys_file_info").Safe()
)

func RemoveOld(oldFile string, newfile string) error {
	if gconv.String(oldFile) != gconv.String(newfile) {
		model := Model
		oldData, err := model.Where("file_url", oldFile).One()
		if err != nil {
			return err
		}
		editData := g.Map{
			"times": oldData["times"].Uint() - 1,
		}

		_, err = model.Where("file_url", oldFile).Update("times", editData)
		if err != nil {
			return err
		}
	}
	return nil
}

func UpdateMedia() error {
	return nil
}
